/*
// +----------------------------------------------------------------------
// | 南昌速翔网络科技有限公司
// +----------------------------------------------------------------------
// | QQ技术：1424445608   电话/微信：15622289461
// +----------------------------------------------------------------------
// | 请务必尊重知识产权 严格保证不恶意传播产品源码、不得直接对产品本身
// | 进行二次转售或倒卖、不得对产品进行简单包装后声称为自己的产品等。
// | 否则我们有权利收回产品，并根据事态轻重追究相应法律责任。
// +----------------------------------------------------------------------
// | Copyright (c) 2019-2020 http://www.suxiangw.com/ All rights reserved.
// +----------------------------------------------------------------------
*/
// alert('3')

i = 0;
j = 0;
count = 0;
MM = 0;
SS = 60; // 秒 90s
MS = 0;
totle = (MM + 1) * 600;
d = 180 * (MM + 1);
MM = "0" + MM;

var gameTime;

// var gameTime = 5;
var zanting = false;
var jinbi = 0;
var shangxian = false;
//count down
var showTime = function() {
    if(!_getPrefs('_token',true)){
      api.closeFrame();
      return;
    }
    if (zanting) {
        return;
    }
    // if (_is_video()) {
    //   return;
    // }

    if (totle == 0) {

        clearInterval(s);
        clearInterval(t1);
        ajax();
        return;

    } else {
        if (totle > 0 && MS > 0) {
            MS = MS - 1;
            if (MS < 10) {
                MS = "0" + MS
            };
        };
        if (MS == 0 && SS > 0) {
            MS = 10;
            SS = SS - 1;
            if (SS < 10) {
                SS = "0" + SS
            };
        };
        if (SS == 0 && MM > 0) {
            SS = 60;
            MM = MM - 1;
            if (MM < 10) {
                MM = "0" + MM
            };
        };
    };
    totle = totle - 1;
    //  $(".time").html(SS + "s");
  //  console.log(SS)
  //  dGltZS5qcw0K5Y2X5piM6YCf57+U572R57uc56eR5oqA5pyJ6ZmQ5YWs5Y+4IA0KUVHmioDmnK/vvJoxNDI0NDQ1NjA4ICAg55S16K+dL+W+ruS/oe+8mjE1NjIyMjg5NDYxDQror7fliqHlv4XlsIrph43nn6Xor4bkuqfmnYMg5Lil5qC85L+d6K+B5LiN5oG25oSP5Lyg5pKt5Lqn5ZOB5rqQ56CB44CB5LiN5b6X55u05o6l5a+55Lqn5ZOB5pys6LqrDQrov5vooYzkuozmrKHovazllK7miJblgJLljZbjgIHkuI3lvpflr7nkuqflk4Hov5vooYznroDljZXljIXoo4XlkI7lo7Dnp7DkuLroh6rlt7HnmoTkuqflk4HnrYnjgIINCkNvcHlyaWdodCAoYykgMjAxOC0yMDE5IGh0dHA6Ly93d3cuc3V4aWFuZ3cuY29tLyBBbGwgcmlnaHRzIHJlc2VydmVkLg==

};

var start1 = function() {
    if(!_getPrefs('_token',true)){
      api.closeFrame();
      return;
    }
    if (zanting) {
        return
    }
    // if (_is_video()) {
    //   return;
    // }
    //i = i + 0.6;
    i = i + 360 / ((gameTime) * 10); //旋转的角度  90s 为 0.4  60s为0.6
    count = count + 1;
    if (count <= (gameTime / 2 * 10)) { // 一半的角度  90s 为 450
        $(".pie1").css("-o-transform", "rotate(" + i + "deg)");
        $(".pie1").css("-moz-transform", "rotate(" + i + "deg)");
        $(".pie1").css("-webkit-transform", "rotate(" + i + "deg)");
    } else {
        $(".pie2").css("backgroundColor", "#d13c36");
        $(".pie2").css("-o-transform", "rotate(" + i + "deg)");
        $(".pie2").css("-moz-transform", "rotate(" + i + "deg)");
        $(".pie2").css("-webkit-transform", "rotate(" + i + "deg)");
    }
};

var start2 = function() {
    j = j + 0.6;
    count = count + 1;
    if (count == 300) {
        count = 0;
        //  clearInterval(t2);
        t1 = setInterval("start1()", 100);
    }
    $(".pie2").css("-o-transform", "rotate(" + j + "deg)");
    $(".pie2").css("-moz-transform", "rotate(" + j + "deg)");
    $(".pie2").css("-webkit-transform", "rotate(" + j + "deg)");
}

var countDown = function() {

        $('.pie1').removeAttr('style');
        $('.pie2').removeAttr('style');
        //80*80px 时间进度条
        i = 0;
        j = 0;
        count = 0;
        MM = 0;
        SS = gameTime;
        MS = 0;
        totle = (MM + 1) * gameTime * 10;
        d = 180 * (MM + 1);
        MM = "0" + MM;
        showTime();
        s = setInterval("showTime()", 100);
        start1();
        //start2();
        t1 = setInterval("start1()", 100);
    }
    // 暂停倒计时
function t(a) {
  // alert(a)
  // console.log("zanting:"+zanting)
  zanting = a;
  if(!zanting){
    dongzuo();
  }
}
function donghua(){
  setTimeout(function() {
      $('.time span').addClass('animated flipInY');
      $('.time span').text('+'+jinbi);
      $('.time span').one('webkitAnimationEnd',  function(ret) {
          $('.game_time').removeClass('animated bounce');
          $('.time span').removeClass('animated flipInY');
          setTimeout(function() {
              var _this = $('.time span');
              _this.addClass('animated bounceOutUp');
              _this.one('webkitAnimationEnd',  function(ret) {
                  _this.removeClass('animated bounceOutUp');
                  _this.addClass('animated flipInY');
                  _this.html('<img src="../i/time_jinbi.png" />');
                  $('.pie1').removeAttr('style');
                  $('.pie2').removeAttr('style');
                  setTimeout(function() {
                      _this.removeClass('animated flipInY');
                      t(false);
                      dongzuo();
                      countDown();
                  }, 1000)
              });
          }, 2000);
      });
  }, 1000)
}
// 请求网络
function ajax() {
    if(!_getPrefs('_user')){
      return login_tiao();
    }
    _ajax("renwu/time_jinbi_add", function(ret, err) {
      // console.log(JSON.stringify(ret)+JSON.stringify(err));
        if (ret) {
            if(ret.jinbi){
              jinbi = ret.jinbi;
              donghua();
              return;
            }
        }else{

          // clearInterval(s);
          // clearInterval(t1);

        }

        api.closeFrame();
    })
}
function jinbi_msg(){
  // 弹窗
  var url = 'jinbi_msg';
  api.openFrame({
    name: url,
    url: _h_w + url + '.html',
    rect: {
      x: 0,
      y: 0,
      w: 'auto',
      h: 'auto',
    },
    pageParam: {
      jinbi: jinbi
    },
    bgColor: 'rgba(0,0,0,0)',
  })
}
